﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LogicaNegocio;
using Entidades;

namespace UI
{
    public partial class FrmCliente_Buscar : Form
    {
        public FrmCliente_Buscar(bool seleccionar)
        {
            InitializeComponent();
           // this.dgvCliente.AutoGenerateColumns = false;
            this.btnSeleccionar.Visible = seleccionar;
        }

        private void btnSalir_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnBuscar_Click(object sender, EventArgs e)
        {            
            this.ptbLoading.Visible = true;
            this.btnBuscar.Enabled = false;
            this.bgwBuscar.RunWorkerAsync();
        }

        private void bgwBuscar_DoWork(object sender, DoWorkEventArgs e)
        {
            this.bgwBuscar.ReportProgress(0, "Busando...");
            try
            {
                ClienteLN cliente = new ClienteLN();
                this.bgwBuscar.ReportProgress(1, cliente.BusquedaAvanzada(this.txtCadenaDeBusqueda.Text));
                this.bgwBuscar.ReportProgress(2, "");
            }
            catch (Exception ex)
            {
                this.bgwBuscar.ReportProgress(3, ex.Message);
            }            
        }

        private void bgwBuscar_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            this.lblMensaje.Text = e.UserState.ToString();
            if (e.ProgressPercentage==1)
            {
                this.dgvCliente.DataSource =e.UserState;
            }
        }

        private void bgwBuscar_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            this.ptbLoading.Visible = false;
            this.btnBuscar.Enabled = true;
        }

        private void btnSeleccionar_Click(object sender, EventArgs e)
        {
            if (this.dgvCliente.SelectedRows.Count>0)
            {
               
            }
        }       
    }
}
